package camid.services.nameservice;

import java.io.Serializable;

import camid.distribution.lifecycle.LifecycleScope;
import camid.distribution.lifecycle.LocationScope;
import camid.distribution.lifecycle.ManagedObject;

public class EntityMetadata implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4853593306214469621L;

	private String entityType;
	
	private LifecycleScope lifeCycleScope;
	
	private LocationScope locationScope;
	
	public EntityMetadata(String entityType, LifecycleScope scope, LocationScope locationScope) {
		super();
		this.entityType = entityType;
		this.lifeCycleScope = scope;
		this.locationScope = locationScope;
	}

	public String getEntityType() {
		return entityType;
	}

	public void setEntityType(String entityType) {
		this.entityType = entityType;
	}
	
	public LifecycleScope getLifeCycleScope() {
		return lifeCycleScope;
	}

	public void setLifeCycleScope(LifecycleScope lifeCycleScope) {
		this.lifeCycleScope = lifeCycleScope;
	}

	public LocationScope getLocationScope() {
		return locationScope;
	}

	public void setLocationScope(LocationScope locationScope) {
		this.locationScope = locationScope;
	}

	public static EntityMetadata extractEntityMetadata( String entityType )
	{
		EntityMetadata metadata = null;
		try 
		{
			Class<?> entityClass = Class.forName(entityType);
			if(entityClass.isAnnotationPresent(ManagedObject.class))
			{
				ManagedObject mobj = entityClass.getAnnotation(ManagedObject.class);
				metadata = new EntityMetadata(entityType, mobj.lifecycleScope(), mobj.locationScope());
			}
		}
		catch (ClassNotFoundException e) 
		{
			//Do nothing.
		}
		return metadata;
	}
}
